#pragma once

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;

std::string UTF8_to_ANSI (const char* szUTF8);
std::string ANSI_to_UTF8 (const char* szANSI);

//the following functions have not been tested
//they are borrowed from http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=2896


#define SPACES " \t\r\n"
inline string trim_right (const string & s, const string & t = SPACES);
inline string trim_left (const string & s, const string & t = SPACES);
inline string trim (const string & s, const string & t = SPACES);

// returns a lower case version of the string 
string tolower (const string & s);

// returns an upper case version of the string 
string toupper (const string & s);

// transformation function for tocapitals that has a "state"
// so it can capitalise a sequence
class fCapitals : public unary_function<char,char> 
{
	bool bUpper;
	
public:
	
	// first letter in string will be in capitals
	fCapitals () : bUpper (true) {}; // constructor
	
	char operator() (const char & c)  
    { 
		char c1;
		// capitalise depending on previous letter
		if (bUpper)
			c1 = toupper (c);
		else
			c1 = tolower (c);
		
		// work out whether next letter should be capitals
		bUpper = isalnum (c) == 0;
		return c1; 
    }
};  // end of class fCapitals

// returns a capitalized version of the string 
string tocapitals (const string & s);


// split a line into the first word, and rest-of-the-line
string GetWord (string & s, 
                const string delim = " ",
                const bool trim_spaces = true);

// To be symmetric, we assume an empty string (after trimming spaces)
// will give an empty vector.
// However, a non-empty string (with no delimiter) will give one item
// After that, you get an item per delimiter, plus 1.
// eg.  ""      => empty
//      "a"     => 1 item
//      "a,b"   => 2 items
//      "a,b,"  => 3 items (last one empty)

void StringToVector (const string s, 
                     vector<string> & v,
                     const string delim = " ", 
                     const bool trim_spaces = true);

// Takes a vector of strings and converts it to a string 
// like "apples,peaches,pears" 
// Should be symmetric with StringToVector (excepting any spaces that might have
//  been trimmed).
string VectorToString (const vector<string> & v, 
                       const string delim = " ");
